package com.huang.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huang.eduservice.entity.EduCourse;
import com.huang.eduservice.entity.EduPublish;
import com.huang.eduservice.mapper.EduCourseMapper;
import com.huang.eduservice.mapper.EduPublishMapper;
import com.huang.eduservice.service.EduCourseService;
import com.huang.eduservice.service.EduPublishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EduPublishServiceImpl extends ServiceImpl<EduPublishMapper, EduPublish> implements EduPublishService {


    @Override
    public List<EduPublish> getPublishType() {
        Map<Object, Object> map = new HashMap<>();
        List<EduPublish> res = baseMapper.selectList(null);
        for (int i = 0; i < res.size(); i++) {
            if (!map.containsKey(res.get(i).getPublish())) {
                map.put(res.get(i).getPublish(), 1);
            } else {
                res.remove(i);
            }
        }
        return res;
    }

    @Override
    public EduPublish getPublish(String courseId) {
        EduPublish one = baseMapper.selectOne(new QueryWrapper<EduPublish>().eq("course_id", courseId));
        return one;
    }
}
